package BIO.chat_demo;

import BIO.test04.HandlerSocketServerPool;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * 目标：BIO模式下的端口转发思想-服务端实现
 * 需求：
 * 1.注册端口
 * 2.接收客户端的socket连接，交给独立的线程处理
 * 3.把当前连接的客户端socket存入到一个集合中保存
 * 4.接收客户端消息，然后推送到当前所有在线的socket接收
 */
public class Server {
    public static final List<Socket> socketList = new ArrayList<>();
    public static void main(String[] args) {
        socketList.clear();
        HandlerSocketServerPool pool = new HandlerSocketServerPool(3,10,10);
        try {
            ServerSocket ss = new ServerSocket(9999);
            while (true){
                Socket socket= ss.accept();
                //把登录的客户端存入到集合中
                socketList.add(socket);
                pool.execute(new ServerReaderThread(socket));
            }
        }catch (Exception e){

        }
    }
}
